# -*- coding: utf-8 -*-
import xlrd

filepath = "./B-2廖铸_现有目录.xls"
data = xlrd.open_workbook(filepath)
names = data.sheet_names()

for name in names:
    table = data.sheet_by_name(name)
    data.sheet_loaded(name)
    max_rows = table.nrows

    sheet_name = []
    sheet_head = []
    sheet_data = []
    temp_data = []
    """取数据"""
    j = 0
    k = 0
    l = 0
    for i in range(max_rows):
        j += 1
        if j > 4:
            if '\u4e00' <= table.row_values(i)[0] <= '\u9fa5':
                k += 1
                sheet_name.append("第" + table.row_values(i)[0] + "类")

                temp_head = []
                temp_head.append(table.row_values(i))
                sheet_head.append(temp_head)
                l = 0

                if len(temp_data) != 0:
                    sheet_data.append(temp_data)
                    temp_data = []
            elif "（" in table.row_values(i)[0]:
                l += 1

                temp_head = table.row_values(i)[:]
                temp_head[0] = str(k) + "-" + str(l)
                sheet_group = []

                if l == 1:
                    del sheet_name[-1]

                    del sheet_head[-1]
                    sheet_group.append(table.row_values(i - l))
                    sheet_group.append(temp_head)
                    sheet_head.append(sheet_group)
                else:
                    sheet_group.append(temp_head)
                    sheet_head.append(sheet_group)

                sheet_name.append("第" + str(k) + "-" + str(l) + "类")

                if len(temp_data) != 0:
                    sheet_data.append(temp_data)
                    temp_data = []
            else:
                temp_data.append(table.row_values(i))

    sheet_data.append(temp_data)
    # print(sheet_name)
    # print(sheet_head)
    # print(sheet_data)

    # num = 1
    # for i in sheet_data:
    #     print(num, "---", i)
    #     num += 1
    temp = []
    num = 0
    for i in sheet_head:
        i.extend(sheet_data[num])
        temp.append(i)
        num += 1

    # print(temp)
